package com.itheima.user.controller;

import com.itheima.common.pojo.User;
import com.itheima.common.vo.UserOrderVO;
import com.itheima.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据用户名查询用户对象
     * @param username 用户名
     * @return 用户对象
     */
    @GetMapping("/query")
    public ResponseEntity<User> findUserByUsername(@RequestParam("username")String username){
        User user=userService.findUserByUsername(username);
        return ResponseEntity.ok(user);
    }

    /**
     * 根据用户名查询用户对应的所有订单信息
     * @param username 用户名
     * @return 用户订单信息
     */
    @GetMapping("queryUserOrderVO")
    public ResponseEntity<UserOrderVO> queryUserOrderVOByUsername(@RequestParam("username") String username){
        UserOrderVO userOrderVO=userService.queryUserOrderVOByUsername(username);

        return ResponseEntity.ok(userOrderVO);
    }
}
